home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmiSoft / Mus / Play / Mhm_mayhem.lha / mhm-mAYhem_deli / hardAY / hardAY_test.c < prev    next >
C/C++ Source or Header  |  2002-08-17  |  5KB  |  283 lines

  1. #include <exec/memory.h>
  2. #include <clib/dos_protos.h>
  3. #include <clib/exec_protos.h>
  4. #include <clib/timer_protos.h>
  5. #include <pragmas/exec_sysbase_pragmas.h>
  6. #include <pragmas/timer_pragmas.h>
  7. #include <pragmas/dos_pragmas.h>
  8. #include <utility/tagitem.h>
  9. #include <dos/dos.h>
  10. #include <dos/dosextens.h>
  11. #include <dos/dostags.h>
  12.  
  13. #include "hardAY.h"
  14.  
  15.  
  16. struct Library * DOSBase, * SysBase;
  17. BPTR inp,outp;
  18.  
  19.  
  20.  
  21. // timer related
  22. struct Library * TimerBase;
  23. struct MsgPort * tmrport;
  24. struct timerequest * tmr_rq;
  25.  
  26. ULONG timer_Init(void);
  27. void  timer_Free(void);
  28. void  timer_Wait(ULONG,ULONG);
  29. void  timer_Start(ULONG,ULONG);
  30. void  timer_BadWaitEnd(void);
  31. void  timer_WaitEnd(void);
  32. void  timer_Prep(ULONG,ULONG);
  33.  
  34.  
  35.  
  36.  
  37. void test_AY(void);
  38.  
  39.  
  40.  
  41. __saveds main()
  42. {
  43.     ULONG timer_res=0;
  44.  
  45.   SysBase = *((struct Library **)4L);
  46.     if(DOSBase = OpenLibrary("dos.library",36))
  47.     {
  48.         inp=Input();outp=Output();
  49.  
  50.         timer_res=timer_Init();
  51.  
  52.         if( timer_res )
  53.         {
  54.             test_AY();
  55.         }
  56.  
  57.         if( timer_res ) timer_Free();
  58.  
  59.         CloseLibrary(DOSBase);
  60.   }
  61.  
  62. }
  63.  
  64.  
  65. void test_AY(void)
  66. {
  67.     ULONG Success;
  68.  
  69.     UBYTE lefttone[]   = { 1,1, 0,00, 7,0xFE,  8,15};
  70.     UBYTE righttone[]  = { 5,1, 4,10, 7,0xFB, 10,15};
  71.     UBYTE centertone[] = { 3,1, 2,20, 7,0xFD,  9,15};
  72.  
  73.     UBYTE lownoise[]  = { 6,31, 7,0xEF, 9,15 };
  74.     UBYTE highnoise[] = { 6,1,  7,0xEF, 9,15 };
  75.  
  76.     UBYTE lsenv[] =  { 3,1, 2,60, 7,0xFD, 9,16, 12,5, 11,0, 13,0x0A };
  77.     UBYTE hsenv[] =  { 3,1, 2,60, 7,0xFD, 9,16, 12,0, 11,10, 13,0x0A };
  78.     UBYTE hsenvl[] = { 1,1, 0,60, 7,0xFE, 8,16, 12,0, 11,10, 13,0x0A };
  79.     UBYTE hsenvr[] = { 5,1, 4,60, 7,0xFB, 10,16, 12,0, 11,10, 13,0x0A };
  80.     UBYTE puenv[] =  { 7,0xFF, 9,16, 12,0, 11,30, 13,0x0A };
  81.  
  82.     Success=hardAY_On();
  83.  
  84.     if( !Success )
  85.     {
  86.         Printf("Now AY is shut up\n");
  87.         hardAY_Shut();
  88.         Printf("Frequency is set to 1.750000 MHz\n");
  89.         hardAY_SetFreq(1750000);
  90.         timer_Wait(1,0);
  91.  
  92.         Printf("\nNow AY is generating tone:\n Left\n");
  93.         hardAY_WrRegList(lefttone,4);
  94.         timer_Wait(2,0);
  95.         hardAY_Shut();
  96.         timer_Wait(1,0);
  97.         Printf(" Right\n");
  98.         hardAY_WrRegList(righttone,4);
  99.         timer_Wait(2,0);
  100.         hardAY_Shut();
  101.         timer_Wait(1,0);
  102.         Printf(" Center\n");
  103.         hardAY_WrRegList(centertone,4);
  104.         timer_Wait(2,0);
  105.         hardAY_Shut();
  106.         timer_Wait(1,0);
  107.  
  108.         Printf("\nNow AY is generating noise:\n Low-frequency\n");
  109.         hardAY_WrRegList(lownoise,3);
  110.         timer_Wait(2,0);
  111.         hardAY_Shut();
  112.         timer_Wait(1,0);
  113.         Printf(" High-frequency\n");
  114.         hardAY_WrRegList(highnoise,3);
  115.         timer_Wait(2,0);
  116.         hardAY_Shut();
  117.         timer_Wait(1,0);
  118.  
  119.         Printf("\nNow AY is generating envelope:\n Low-speed\n");
  120.         hardAY_WrRegList(lsenv,7);
  121.         timer_Wait(5,0);
  122.         hardAY_Shut();
  123.         timer_Wait(1,0);
  124.         Printf(" High-speed\n");
  125.         hardAY_WrRegList(hsenv,7);
  126.         timer_Wait(2,0);
  127.         hardAY_Shut();
  128.         timer_Wait(1,0);
  129.  
  130.         hardAY_WrRegList(hsenvl,7);
  131.         timer_Wait(2,0);
  132.         hardAY_Shut();
  133.         timer_Wait(1,0);
  134.  
  135.         hardAY_WrRegList(hsenvr,7);
  136.         timer_Wait(2,0);
  137.         hardAY_Shut();
  138.         timer_Wait(1,0);
  139.  
  140.         Printf(" Without tone\n");
  141.         hardAY_WrRegList(puenv,5);
  142.         timer_Wait(2,0);
  143.         hardAY_Shut();
  144.         timer_Wait(1,0);
  145.  
  146.         Printf("\nNow frequency of AY will be changed:\n 1.750000 MHz\n");
  147.         hardAY_SetFreq(1750000);
  148.         hardAY_WrRegList(centertone,4);
  149.         timer_Wait(3,0);
  150.         Printf(" 1.773448 MHz\n");
  151.         hardAY_SetFreq(1773448);
  152.         timer_Wait(3,0);
  153.         Printf(" 1.000000 MHz\n");
  154.         hardAY_SetFreq(1000000);
  155.         timer_Wait(3,0);
  156.         Printf(" 2.000000 MHz\n");
  157.         hardAY_SetFreq(2000000);
  158.         timer_Wait(3,0);
  159.         hardAY_Shut();
  160.  
  161.         timer_Wait(1,0);
  162.         Printf("\nTests passed... Have you heard anything? %%)\n\n");
  163.  
  164.         hardAY_Off();
  165.   }
  166.     else
  167.     {
  168.         if( Success==2 )
  169.         {
  170.             Printf("Can't allocate parallel port!\n");
  171.         }
  172.         else if( Success==1 )
  173.         {
  174.             Printf("No connected AY found! Check hardware.\n");
  175.         }
  176.         else
  177.         {
  178.             Printf("Unknown error %\\n");
  179.         }
  180.     }
  181. }
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- **
  197. **    functions for working with timer    **
  198. ** -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
  199.  
  200. ULONG timer_Init(void)
  201. {
  202.  
  203.     tmrport=CreateMsgPort();
  204.     if( !tmrport )
  205.     {
  206.         Printf("aprg: Can't create msgport!\n");
  207.         return 0;
  208.     }
  209.  
  210.     tmr_rq=(struct timerequest *)CreateIORequest(tmrport,sizeof(struct timerequest));
  211.     if( !tmr_rq )
  212.     {
  213.         Printf("aprg: Can't create IORequest!\n");
  214.         DeleteMsgPort(tmrport);
  215.         return 0;
  216.     }
  217.  
  218.     if( OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest *)tmr_rq,0) )
  219.     {
  220.         Printf("aprg: Can't open %s!\n",TIMERNAME);
  221.         DeleteIORequest(tmr_rq);
  222.         DeleteMsgPort(tmrport);
  223.         return 0;
  224.     }
  225.  
  226.     TimerBase=(struct Library *)tmr_rq->tr_node.io_Device;
  227.  
  228.     return 1;
  229. }
  230.  
  231. void timer_Free(void)
  232. {
  233.     CloseDevice((struct IORequest *)tmr_rq);
  234.     DeleteIORequest(tmr_rq);
  235.     DeleteMsgPort(tmrport);
  236. }
  237.  
  238. void timer_Wait(ULONG secs,ULONG usecs)
  239. {
  240.     timer_Prep(secs,usecs);
  241.  
  242.     DoIO( (struct IORequest *)tmr_rq );
  243. }
  244.  
  245. void timer_Start(ULONG secs,ULONG usecs)
  246. {
  247.     timer_Prep(secs,usecs);
  248.  
  249.     SendIO( (struct IORequest *)tmr_rq );
  250. }
  251.  
  252. void timer_BadWaitEnd(void)
  253. // timer_WaitEnd() MUST be used after this function
  254. {
  255.     ULONG sigmask;
  256.  
  257.     sigmask=1<<(tmrport->mp_SigBit);
  258.  
  259.     while( !(SetSignal(0L,sigmask)&sigmask) );
  260. }
  261.  
  262. void timer_WaitEnd(void)
  263. {
  264.     WaitIO( (struct IORequest *)tmr_rq );
  265. }
  266.  
  267. void timer_Prep(ULONG secs,ULONG usecs)
  268. {
  269.     ULONG s,us;
  270.  
  271.     s=secs;us=usecs;
  272.  
  273.     if( us>999999 )
  274.     {
  275.         s+=us/1000000;us%=1000000;
  276.     }
  277.  
  278.   tmr_rq->tr_node.io_Command = TR_ADDREQUEST;
  279.     tmr_rq->tr_time.tv_secs    = s;
  280.     tmr_rq->tr_time.tv_micro   = us;
  281. }
  282.  
  283.